========
========
filepath = "https://raw.githubusercontent.com/shabanm2/Utqiagvik/main/Analysis_Ready_Data/"
years = c("2022", "2023")
seasons = c("Spring", "Summer","Fall")
sites = c("TNHA", "BEO", "SSMH")
# put season values for the season that has the start of the data
date_start = "2022-06-01" # data starts in June 2022 (YEAR-MO-DY) where day is always 01
# put season values for the season that has the last of the data
date_end = "2023-11-01" # data ends after November of 2023 (will get data up UNTIL date_end not after)
scree = F # scree plot
eigen = T # eigenvectors and eigenvalues
spring_months = c("March", "April", "May")
summer_months = c("June","July","August")
fall_months = c("September", "October", "November")
winter_months = c("December", "January", "February")
spring_dates = data.frame(months=spring_months, start=c("-03-01","-04-01","-05-01"), end=c("-04-01","-05-01","-06-01"))
summer_dates = data.frame(months=summer_months, start=c("-06-01","-07-01","-08-01"), end=c("-07-01","-08-01","-09-01"))
fall_dates = data.frame(months=fall_months, start=c("-09-01","-10-01","-11-01"), end=c("-10-01","-11-01","-12-01"))
winter_dates = data.frame(months=winter_months, start=c("-12-01","-01-01","-02-01"), end=c("-01-01","-02-01","-03-01"))
all_dates = data.frame(matrix(nrow = 0, ncol = 4))
for(yur in years){
# spring
if("Spring" %in% seasons){
for(i in c(1:3)){
curdate = as.Date(paste0(yur, spring_dates[i, 2]))
if(curdate >= date_start && curdate < date_end){
all_dates <- rbind(all_dates, c(spring_dates[i,1], paste0(yur, spring_dates[i, 2]), paste0(yur, spring_dates[i, 3]),"Spring"))
}
}
}
if("Summer" %in% seasons){
for(i in c(1:3)){
curdate = as.Date(paste0(yur, summer_dates[i, 2]))
if(curdate >= date_start && curdate < date_end){
all_dates <- rbind(all_dates, c(summer_dates[i,1], paste0(yur, summer_dates[i, 2]), paste0(yur, summer_dates[i, 3]),"Summer"))
}
}
}
if("Fall" %in% seasons){
for(i in c(1:3)){
curdate = as.Date(paste0(yur, fall_dates[i, 2]))
if(curdate >= date_start && curdate < date_end){
all_dates <- rbind(all_dates, c(fall_dates[i,1], paste0(yur, fall_dates[i, 2]), paste0(yur, fall_dates[i, 3]),"Fall"))
}
}
}
if("Winter" %in% seasons){
for(i in c(1:3)){
curdate = as.Date(paste0(yur, winter_dates[i, 2]))
if(curdate >= date_start && curdate < date_end){
all_dates <- rbind(all_dates, c(winter_dates[i,1], paste0(yur, winter_dates[i, 2]), paste0(yur, winter_dates[i, 3]),"Winter"))
}
}
}
}
colnames(all_dates) = c("months","start","end","szn")
library(dplyr)
library(lubridate)
library(tidyverse)
=========================
=========================
Temporal Range: Season Vertical Spatial Range: 30-45 cm Horizontal Spatial Range: stations across site (TNHA, SSMH, BEO) –> Average Total Site –> North vs South (except for BEO)
pick_site <- function(cursite){
big_df <<- daily %>% filter(site == cursite)
if(szn == "Winter"){
big_df <<- big_df %>% select(-solar)
}
return(big_df)
}
pick_dates <- function(datemin, datemax, big_df){
pca_df <<- big_df %>% filter(Date >= datemin) %>% filter(Date < datemax)
# get rid of NAs
pca_df <<- na.omit(pca_df)
pca_df <<- unique(pca_df)
return(pca_df)
}
calc_pca <- function(pca_df){
pca <<- prcomp(pca_df[,6:(ncol(pca_df)-2)], center=TRUE, scale.=TRUE)
#take out variables
sd <- pca$sdev
loads <<- pca$rotation
rownames(loads) <<- colnames(pca_df[6:(ncol(pca_df)-2)])
scores <<- pca$x
var <- sd^2
varPercent <- var/sum(var) * 100
return(list("pca"=pca, "loads"=loads))
}
make_scree <- function(pca){
sd <- pca$sdev
var <- sd^2
varPercent <- var/sum(var) * 100
barplot(varPercent, xlab="PC", ylab="Percent Variance", names.arg=1:length(varPercent),
las=1, ylim=c(0, max(varPercent)), col="gray")
abline(h=1/ncol(pca_df[5:ncol(pca_df)])*100, col="red")
}
make_eigen <- function(pca){
eigenvectors <- pca$rotation
print("Eigenvectors (Loadings):")
print(eigenvectors)
print("Loadings Cutoff:")
sqrt(1/ncol(pca_df[5:ncol(pca_df)])) # cutoff for "important" loadings
# Access the eigenvalues (variances of the principal components)
eigenvalues <- (pca$sdev)^2
print("Eigenvalues:")
print(eigenvalues)
}
===============
===============
Load all data
daily <- read.csv(paste0(filepath, "daily_2022_2024.csv"))
daily <- daily %>% select(-X) %>% select(-X.1) # get rid of index columns
daily$Date <- as.POSIXct(daily$date, format="%Y-%m-%d") # format dates
daily$fullname[daily$site == "BEO"] <- "BEO-BASE"
daily <- daily %>% filter(fullname == "TNHA-SA" | fullname == "TNHA-SC" | fullname == "SSMH-SB" | fullname == "SSMH-SA" | fullname == "BEO-BASE") %>% select(-c(windspeed, winddir, date)) %>% mutate(aspect = case_when(fullname == "TNHA-SC" | fullname == "SSMH-SB" ~ "North", fullname == "TNHA-SA" | fullname == "SSMH-SA" ~ "South", .default = "N/A")) %>% filter(grounddepth == 8) %>% filter(Date >= "2022-06-19") # create "aspect" column and filter for top depth of soil and start date of when we started collecting data
# note: the data before June 19, 2022 was estimated by our gap-filling script and should be disregarded due to extrapolation
cursite = "BEO"
make_pca <- function(pca_df, szn, yr, cursite){
if (cursite == "BEO")
{
SOUTH <<- pca_df$site == cursite
# n <- "BEO"
} else {
SOUTH <<- pca_df$site == cursite & pca_df$aspect == "South"
NORTH <<- pca_df$site == cursite & pca_df$aspect == "North"
s <- pca_df$fullname[SOUTH][1]
n <- pca_df$fullname[NORTH][1]
}
scaling <- 2
textNudge <- 1.1
limNudge <- 1.3
xlimit <- seq(floor(min(scores[,1])*limNudge),ceiling(max(scores[,1])*limNudge), 1)
ylimit <- seq(floor(min(scores[,2])*limNudge),ceiling(max(scores[,2])*limNudge), 1)
plot(scores[, 1], scores[, 2], xlab="PCA 1", ylab="PCA 2", type="n", asp=1,
las=1, xaxt='n', yaxt='n')
axis(side = 1, at=xlimit)
axis(side = 2, at=ylimit)
if (cursite == "BEO")
{
nvstext <- " "
} else {
nvstext <- " North v. South "
}
mindate = format(as.Date(min(pca_df$Date)), format="%B %d %Y")
maxdate = format(as.Date(max(pca_df$Date)), format="%B %d %Y")
title(paste0(szn, " ", yr," Principal Component Analysis:\n", site, nvstext, "\n(", mindate," - ", maxdate, ")"), adj=0.5)
points(scores[SOUTH, 1], scores[SOUTH, 2], pch=16, cex=1, col="mediumturquoise")
if(cursite != "BEO"){
points(scores[NORTH, 1], scores[NORTH, 2], pch=16, cex=1, col="salmon")
legend(x = "topright", # Position
legend = c(paste0(s, " (south)"), paste0(n, " (north)")), # Legend texts
col = c("mediumturquoise","salmon"),
pch = 19) #colors
} else{
legend(x = "topright", # Position
legend = "BEO", # Legend texts
col = "mediumturquoise",
pch = 19)
}
arrows(0, 0, loads[, 1]* scaling, loads[, 2]* scaling, length=0.1, angle=20, col="darkred", lwd=1.4)
text(loads[1, 1]*scaling*(textNudge+0.4), loads[1, 2]*scaling*textNudge, rownames(loads)[1], col="darkred", cex=1) # ground label
text(loads[2, 1]*scaling*textNudge, loads[2, 2]*scaling*textNudge, rownames(loads)[2], col="darkred", cex=1) # vwc label
if(nrow(loads) > 2){
text(loads[3, 1]*scaling*(textNudge+0.2), loads[3, 2]*scaling*textNudge, rownames(loads)[3], col="darkred", cex=1) # airtemp label
if(nrow(loads)>3){
text(loads[4, 1]*scaling*textNudge-0.2, loads[4, 2]*scaling*textNudge, rownames(loads)[4], col="darkred", cex=1) # solar or wind label
if(nrow(loads)>4){
text(loads[5, 1]*scaling*textNudge, loads[5, 2]*scaling*textNudge, rownames(loads)[5], col="darkred", cex=1) # solar or wind label
}
}
}
#text(-3, 1]*scaling*textNudge, 1, "TNHA-SA \n(south)", col="mediumturquoise")
#text(1, 1, "TNHA-SC \n(north)", col="salmon")
}
for(i in c(1:nrow(all_dates))){
month <- all_dates$months[i]
startdate <- all_dates$start[i]
enddate <- all_dates$end[i]
szn <<- all_dates$szn[i]
yr <<- substr(all_dates$start[i], 1, 4)
for(site in sites){
big_df <- pick_site(site)
pca_df <- pick_dates(startdate, enddate, big_df)
if(nrow(pca_df) > 4){
p <- calc_pca(pca_df)
pca <- p$pca
loads <- p$loads
if(scree == T){
make_scree(pca)
}
if(eigen == T){
make_eigen(pca)
}
make_pca(pca_df, szn, yr, site)
}
}
}
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5986657 0.3520771 -0.1852252 0.6952213
## vwc 0.3497407 -0.6382762 0.6568464 0.1970727
## airtemp 0.5160656 0.4900233 0.3788869 -0.5916064
## solar 0.5029484 -0.4780401 -0.6250513 -0.3575354
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.8444270 1.4002545 0.4447133 0.3106052
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.6320043 -0.10155486 0.2594335 0.72315382
## vwc -0.4320496 -0.06244026 0.8984837 0.04648986
## airtemp 0.5985309 -0.30968850 0.3011983 -0.67463573
## solar -0.2359331 -0.94333496 -0.1862816 0.14054849
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.1217731 0.9581183 0.7430162 0.1770923
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.60221270 0.04045701 -0.2173675 -0.7671079
## vwc -0.08196039 0.94451262 -0.2572712 0.1870560
## airtemp -0.55808103 -0.30329673 -0.5213647 0.5698557
## solar -0.56494948 0.11945812 0.7840547 0.2276403
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.57970306 1.07922373 0.25503784 0.08603537
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5082346 -0.6230756 0.07233704 -0.5901201
## vwc -0.4889326 -0.1668570 -0.78530439 -0.3411755
## airtemp 0.5152861 -0.2318671 -0.54185851 0.6221794
## solar 0.4869525 0.7281299 -0.29060923 -0.3850330
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.8353287 0.4824615 0.4584395 0.2237704
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.58661526 0.03427599 -0.4216422 0.69059797
## vwc -0.09845238 -0.98057910 0.1580632 0.06154489
## airtemp -0.58894072 -0.04473188 -0.3639029 -0.72022396
## solar -0.54711835 0.18785324 0.8153579 0.02375113
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.5557242 1.0059014 0.2999332 0.1384411
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5910477 -0.3394008 0.09337171 -0.72577644
## vwc -0.3446825 -0.7349809 -0.58382412 -0.01210196
## airtemp 0.5645292 -0.4247829 0.18732474 0.68247762
## solar 0.4616962 0.4051785 -0.78443646 0.08559441
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.3696841 0.9899503 0.5388998 0.1014658
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5980340 -0.2675558 -0.2134573 0.7247105
## vwc -0.4449876 0.4482994 -0.7036226 0.3254671
## airtemp 0.5458385 0.0623383 -0.5825568 -0.5990006
## solar 0.3826247 0.8506206 0.3463794 0.1003202
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.43552423 0.76934354 0.71664830 0.07848393
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5787844 -0.3151290 -0.1064790 -0.744556599
## vwc -0.4691883 -0.1927139 -0.8464296 -0.162112804
## airtemp 0.5444147 -0.4183718 -0.3305446 0.647547661
## solar 0.3853357 0.8297711 -0.4036823 0.006077458
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.61831892 0.75773352 0.54924814 0.07469942
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5683906 0.1254251 -0.2382477 -0.77745657
## vwc -0.4341356 -0.7190374 0.5415306 0.03544229
## airtemp -0.5314408 -0.1213217 -0.6237950 0.56011734
## solar -0.4539042 0.6727071 0.5107469 0.28385505
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.86358707 0.65658862 0.41171445 0.06810986
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5922351 -0.01664979 -0.3754989 -0.71272784
## vwc 0.3359343 0.89847212 -0.2094928 -0.18975979
## airtemp -0.5715021 0.26542985 -0.3875443 0.67286089
## solar -0.4580297 0.34931021 0.8154279 -0.05717053
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.53934169 0.85126278 0.54621829 0.06317724
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.66312571 0.07101897 -0.2231793 -0.7109231
## vwc -0.01013416 0.76937841 0.6289690 -0.1111403
## airtemp -0.61853108 0.29443368 -0.2491619 0.6845776
## solar -0.42140349 -0.56242509 0.7017887 0.1165751
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.0986459 1.4673020 0.3284115 0.1056406
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.4951178 0.5026044 0.6154417 0.3513953
## vwc -0.4607260 -0.6285938 -0.1969305 0.5948275
## airtemp -0.5002717 0.4713195 -0.7152990 -0.1262279
## solar -0.5406646 -0.3607167 0.2660776 -0.7118764
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.7161020 0.9265738 0.2193014 0.1380228
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5868166 0.1226013 0.3399548 0.72460051
## vwc -0.4139702 0.7922361 -0.3100207 -0.32384844
## airtemp -0.5412439 -0.3434879 0.4748450 -0.60298702
## solar -0.4374128 -0.4892310 -0.7502267 0.08051672
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.6470678 0.7828465 0.5436596 0.0264261
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.55204683 0.22635770 0.7805485 0.1864151
## vwc 0.56823344 0.28048593 0.4677073 -0.6161885
## airtemp -0.07874073 0.93057359 -0.3465552 0.0879330
## solar -0.60510738 -0.06420779 -0.2278015 -0.7601506
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.67098452 1.10620451 0.21162542 0.01118556
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.70286298 -0.09386910 -0.2664683 0.6528146
## vwc -0.06347246 0.71965895 0.6271405 0.2911307
## airtemp -0.70539124 -0.03566813 0.2727895 -0.6532510
## solar -0.06616701 0.68702792 -0.6791725 -0.2496782
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.7844368 1.2421335 0.8653229 0.1081067
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5504574 -0.4200116 0.0296299 0.7209084
## vwc -0.4959542 0.3110350 0.7775893 -0.2294373
## airtemp -0.5348631 -0.4196601 -0.3615392 -0.6380409
## solar -0.4061373 0.7421138 -0.5135818 0.1433642
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.80663307 0.79054900 0.38399374 0.01882418
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.4261001 0.4944219 -0.7557279 0.05348844
## vwc 0.6174598 0.3122773 -0.1930760 -0.69566372
## airtemp -0.1783060 0.7734228 0.6079611 0.02018645
## solar -0.6367018 -0.2446365 0.1482578 -0.71608902
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.252622007 1.240740009 0.503743008 0.002894976
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5385681 0.22994007 -0.71448153 -0.3828682
## vwc 0.5459460 0.19963389 0.69898699 -0.4165410
## airtemp 0.1865741 -0.94814477 -0.02739819 -0.2558534
## solar 0.6140663 -0.09107891 0.01351582 0.7838651
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.5565577 1.0097921 0.3888418 0.0448084
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5638844 -0.02873009 0.4475307 0.69348773
## vwc -0.5076476 0.42663044 0.7467484 -0.05145173
## airtemp 0.5625199 -0.11012366 0.3958906 -0.71743626
## solar 0.3284809 0.89723677 -0.2921537 -0.04138470
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.8473907 0.8387766 0.2030876 0.1107452
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.50226251 -0.49829710 -0.4337834 -0.55791069
## vwc 0.63375097 -0.03578743 -0.7703462 0.06038023
## airtemp 0.04792933 -0.80402231 0.1222372 0.57992152
## solar 0.58634022 -0.32243973 0.4510619 -0.59057677
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.2048968 1.4570236 0.1887561 0.1493235
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.68959430 0.02181215 0.1770895 -0.701871254
## vwc -0.06400526 -0.86466589 -0.4904678 -0.087735804
## airtemp -0.69350362 -0.08355649 0.1113594 0.706873481
## solar -0.19853402 0.49486911 -0.8459786 -0.003008824
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.9152929 1.0227660 0.9418116 0.1201295
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5611169 -0.1168561 0.2533055 0.77931299
## vwc 0.5306045 -0.2934174 -0.7759851 -0.17381647
## airtemp 0.5542266 -0.1275956 0.5617898 -0.60078652
## solar 0.3105471 0.9401969 -0.1344456 -0.03891851
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 3.03126948 0.79787918 0.12714396 0.04370737
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.6040892 -0.07982983 -0.4142531 -0.67609012
## vwc 0.1200039 0.97046194 0.1750955 -0.11464834
## airtemp 0.6192920 0.06206213 -0.2932512 0.72569235
## solar 0.4869832 -0.21904136 0.8436467 -0.05593318
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.37903426 1.00673131 0.54413757 0.07009687
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5687800 0.10433089 0.6056672 0.5466000
## vwc 0.5592710 -0.05329457 -0.7756432 0.2876688
## airtemp 0.5554766 0.34114523 0.0982017 -0.7519456
## solar 0.2348427 -0.93268145 0.1479909 -0.2303322
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.69606914 0.96677257 0.24296240 0.09419589
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5219017 -0.3938881 -0.6053452 -0.4539030
## vwc 0.1311257 0.8300378 -0.5258216 0.1317381
## airtemp 0.6493928 -0.1524107 0.1061061 0.7374289
## solar -0.5373208 -0.3642257 -0.5880564 0.4825098
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.8151187 1.1160805 0.6996553 0.3691455
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.6204449 -0.1190080 0.2886147 0.71943502
## vwc -0.1964299 -0.9239047 -0.2371584 -0.22709293
## airtemp -0.5969095 0.1788478 0.4258409 -0.65602743
## solar -0.4692146 0.3166237 -0.8240855 -0.02168077
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.42047493 1.02570160 0.53638341 0.01744006
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.2263555 0.85006523 -0.006399035 -0.4755117
## vwc 0.5401260 -0.50203963 0.206338328 -0.6431521
## airtemp 0.5980573 0.15681254 0.553946003 0.5575672
## solar -0.5471330 0.02747983 0.806552772 -0.2221777
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.1062205 1.1870551 0.5551075 0.1516169
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp 0.5299319 -0.4973914 -0.1921442 -0.6594351
## vwc -0.5165330 -0.4302128 0.6815316 -0.2891801
## airtemp 0.6163731 -0.2441167 0.5351846 0.5235157
## solar 0.2691656 0.7126891 0.4606220 -0.4554685
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.7972186 1.3657415 0.5191336 0.3179063
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.6418359 -0.2422262 0.12282388 -0.71713836
## vwc 0.4109931 -0.5194987 0.74635142 -0.06454008
## airtemp -0.5871342 -0.4244813 0.08698354 0.68375644
## solar -0.2727724 0.7009017 0.64831144 0.11842417
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.11954999 1.24094809 0.55058766 0.08891426
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.6226280 0.03763471 0.3134097 0.716025388
## vwc -0.3654349 -0.65612101 -0.6602499 0.005714477
## airtemp -0.6161044 -0.03379869 0.3685708 -0.695290300
## solar -0.3149717 0.75295850 -0.5744562 -0.062019246
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.37398528 1.02585956 0.55362807 0.04652708
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.6115544 -0.20635247 -0.3501414 0.67883789
## vwc -0.1324397 0.97785062 -0.1040470 0.12426626
## airtemp -0.6368495 -0.02354131 -0.2718321 -0.72109350
## solar 0.4504261 -0.02593498 -0.8903272 -0.06132849
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.1119871 0.9961426 0.7193212 0.1725491
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5779887 0.3016412 0.2563170 0.713612815
## vwc 0.3145679 0.8196643 -0.4723529 0.077975457
## airtemp -0.5583625 0.4003731 0.2079869 -0.696185406
## solar -0.5051806 -0.2772443 -0.8172672 0.001568276
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.53865636 0.97611861 0.41484728 0.07037775
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.2239620 -0.93827159 -0.1281475 0.2303599
## vwc -0.6120555 -0.02792341 -0.1278494 -0.7799121
## airtemp -0.5359015 0.09096611 0.7883859 0.2880667
## solar -0.5366923 0.33255358 -0.5879459 0.5056570
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 2.2489468 0.9833098 0.5241253 0.2436181
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5300780 0.4259566 0.65889232 0.3216196
## vwc 0.2021425 -0.7740703 0.56623662 0.1983172
## airtemp -0.5653508 -0.3640985 -0.49014887 0.5545853
## solar -0.5987773 -0.2946326 0.07064764 -0.7413948
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.9582117 1.2902490 0.4171041 0.3344352
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.5178345 0.12391418 0.8449715 -0.05015816
## vwc 0.4214466 -0.69364185 0.3314482 -0.48102578
## airtemp -0.4328080 -0.70444792 -0.1294410 0.54742611
## solar -0.6057288 -0.08520204 -0.3992621 -0.68295169
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.9003721 1.0299971 0.6632886 0.4063422
If you want to just make one plot (for testing):
# look at all_dates and pick a row to use (set to i)
i <- 8
site <- "BEO"
month <- all_dates$months[i]
startdate <- all_dates$start[i]
enddate <- all_dates$end[i]
szn <<- all_dates$szn[i]
yr <<- substr(all_dates$start[i], 1, 4)
big_df <- pick_site(site)
pca_df <- pick_dates(startdate, enddate, big_df)
if(nrow(pca_df > 0)){
p <- calc_pca(pca_df)
pca <- p$pca
loads <- p$loads # not used at the moment
if(scree == T){
make_scree(pca)
}
if(eigen == T){
make_eigen(pca)
}
make_pca(pca_df, szn, yr, site)
}
## [1] "Eigenvectors (Loadings):"
## PC1 PC2 PC3 PC4
## groundtemp -0.68959430 0.02181215 0.1770895 -0.701871254
## vwc -0.06400526 -0.86466589 -0.4904678 -0.087735804
## airtemp -0.69350362 -0.08355649 0.1113594 0.706873481
## solar -0.19853402 0.49486911 -0.8459786 -0.003008824
## [1] "Loadings Cutoff:"
## [1] "Eigenvalues:"
## [1] 1.9152929 1.0227660 0.9418116 0.1201295